package com.example.bookstore.config

import org.jasypt.encryption.StringEncryptor
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder

/**
 * Created by IntelliJ IDEA.
 * User: lvshe
 * Date: 2019/8/13
 * Time: 11:52
 */
@Configuration
class EncryptorConfig {

    companion object {
        const val SECRET = "BOOKSTORE"
    }

    @Bean("jasyptStringEncryptor")
    fun stringEncryptor(): StringEncryptor {
        val encryptor = StandardPBEStringEncryptor()
        encryptor.setPassword(SECRET)
        encryptor.setAlgorithm("PBEWithMD5AndDES")
        return encryptor
    }

    @Bean
    fun passwordEncoder(): BCryptPasswordEncoder {
        return BCryptPasswordEncoder()
    }

}

//fun main() {
//    val encryptor = EncryptorConfig().stringEncryptor()
//    println("url: " + encryptor.encrypt("数据库URL"))
//    println("username: " + encryptor.encrypt("用户名"))
//    println("password: " + encryptor.encrypt("密码"))
//}